import React from "react";
import { Table, Button } from "antd";

// 通过父组件传过来数据
export default function NewsPublish(props) {
  const columns = [
    {
      title: "新闻标题",
      dataIndex: "title",
      // 跳到预览新闻中
      render: (title, row) => (
        <a href={`/news-manage/preview/${row.id}`}>{title}</a>
      ),
    },
    {
      title: "作者",
      dataIndex: "author",
    },
    {
      title: "新闻分类",
      dataIndex: "category",
      render: (category) => <div>{category.label}</div>,
    },
    {
      title: "操作",
      render: (row) => {
        // 使用props.button得到传过来的值,在把当前的id传给父组件
        return <div>{props.button(row.id)}</div>;
      },
    },
  ];
  return (
    <Table
      pagination={{ pageSize: 5 }}
      columns={columns}
      dataSource={props.dataSource}
      rowKey={(item) => item.id}
    />
  );
}
